package demo1;





class Animal {
    protected String name;
    //public String name;
    public int age;


    static {
        System.out.println("Animal::static{静态}");
    }
    {
        System.out.println("Animal::{实例}");
    }

    public void eat() {
        System.out.println(this.name+" 正在吃饭！");
    }

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
        System.out.println("Animal(String name, int age)");
    }
    /*public Animal() {

    }*/
}


// extends 扩展 拓展
class Dog extends Animal {
    public Dog(String name, int age) {
        super(name, age);// 调用父类的构造方法，帮助初始化子类从父类继承过来的成员，并不会生成父类对象
                        //因为本质上是构造子类对象的
        System.out.println("Dog(String name, int age)");
        //super();
    }

    public void bark() {
        System.out.println(this.name+ " 正在旺旺叫！");
    }
}


class Cat extends Animal {
    public Cat(String name, int age) {
        super(name, age);
        System.out.println("Cat(String name, int age)");
    }
    public void miaomiao() {
        System.out.println(this.name+ " 正在喵喵叫！");
    }
}

public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog("圆圆",10);
        //dog.name
        System.out.println("======================");

        Dog dog2 = new Dog("圆圆",10);
    }



    public static void main1(String[] args) {
        Dog dog = new Dog("圆圆",10);
        dog.bark();
        dog.eat();

        System.out.println("====================");

        Cat cat = new Cat("mimi",9);
        cat.miaomiao();
        cat.eat();
    }
}
